package dao.impl;

import dao.PatientDao;
import entity.Patient;
import util.DruidUtils;
import util.PatientRowMapper;

import java.util.List;

/**
 * @Author:
 * @Date: 2020-04-26
 * @Description: @PACKAGE:dao.impl
 * @version: 1.0
 */
public class PatientDaoImpl implements PatientDao {
    @Override
    public List<Patient> getAllPatient() {
        String sql="select * from t_patient";
        List<Patient> list = DruidUtils.commonsSelect(sql,new PatientRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<Patient> getByPatientId(String id) {
        String sql="select * from t_patient where ID ='"+id+"'";
        List<Patient> list = DruidUtils.commonsSelect(sql,new PatientRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<Patient> getByPatientTel(String id) {
        String sql="select * from t_patient where Tel_Number ='"+id+"'";
        List<Patient> list = DruidUtils.commonsSelect(sql,new PatientRowMapper(),new Object[]{});
        return list;
    }


    @Override
    public int add(Patient patient) {
        String sql = "insert  into `t_patient`(`ID`,`Name`,`Sex`,`Age`,`Family_Name`,`Tel_Number`,`Img_Path`,`Pwd`) values (?,?,?,?,?,?,?,?)";

        int i = DruidUtils.executeUpdate(sql,patient.getID(),patient.getName(),patient.getSex(),patient.getAge(),
                patient.getFamily_Name(),patient.getTel_Number(),patient.getImg_Path(),patient.getPwd());

        return i;
    }

    @Override
    public int delete(String PatientID) {
        String sql = "delete from t_patient where ID = ?";
        int i = DruidUtils.executeUpdate(sql,PatientID);

        return i;
    }

    @Override
    public int update(Patient patient) {
        String sql = "update `t_patient` set `Num_Patient`=?,`Name`=?,`Sex`=?,`Age`=?,`Family_Name`=?,`Tel_Number`=?,`Img_Path`=?,`Pwd`=? where `ID`=?";

        int i = DruidUtils.executeUpdate(sql,patient.getNum_Patient(),patient.getName(),patient.getSex(),patient.getAge(),
                patient.getFamily_Name(),patient.getTel_Number(),patient.getImg_Path(),patient.getPwd(),patient.getID());

        return i;
    }

    @Override
    public int updateNoPwdNoPicture(Patient patient) {
        String sql = "update `t_patient` set `Num_Patient`=?,`Name`=?,`Sex`=?,`Age`=?,`Family_Name`=?,`Tel_Number`=? where `ID`=?";

        int i = DruidUtils.executeUpdate(sql,patient.getNum_Patient(),patient.getName(),patient.getSex(),patient.getAge(),
                patient.getFamily_Name(),patient.getTel_Number(),patient.getID());

        return i;
    }
}